package server;

import java.rmi.RemoteException;

import javax.swing.JOptionPane;

import common.Game;
import common.ServerInterface;

//Starts the server, and all it's components
public class ServerMain {
	private final ServerInterface server;

	public ServerMain(final Game game) throws RemoteException {
		this.server = new RMIServer(game);
	}

	public ServerInterface getServer() {
		return this.server;
	}

	public static void main(final String[] arg) {
		final String txt = JOptionPane.showInputDialog(null,
				"Please enter the number of clients that will connect.");
		if (txt == null || txt.equalsIgnoreCase("")) {
			System.exit(0);
		}
		final int nClients = Integer.parseInt(txt);

		try {
			final Game game = new Game(nClients);
			final ServerMain server = new ServerMain(game);
			new ServerGUI(server.getServer()).setVisible(true);
		} catch (final RemoteException e) {
			System.out.println("Creating Server failed!!");
			e.printStackTrace();
		}
	}

}
